package com.lechuang.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lechuang.common.request.PageRequest;
import com.lechuang.system.dto.TenantListDTO;
import com.lechuang.system.entity.TenantInfo;
import com.lechuang.system.service.TenantInfoService;
import com.lechuang.system.mapper.TenantInfoMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author apple
* @description 针对表【tenant_info(商户信息表)】的数据库操作Service实现
* @createDate 2024-06-21 17:01:01
*/
@Service
public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantInfo>
    implements TenantInfoService{

    @Override
    public Page<TenantInfo> pageList(PageRequest<TenantListDTO> pageRequest) {
        Page<TenantInfo> page = new Page<>(pageRequest.getPageNum(), pageRequest.getPageSize());
        TenantListDTO tenantListDTO = pageRequest.getQuery();
        return this.lambdaQuery()
                .and(StrUtil.isNotEmpty(tenantListDTO.getSelectText()), tmp ->
                        tmp.like(TenantInfo::getPhone, tenantListDTO.getSelectText())
                                .or()
                                .like(TenantInfo::getName, tenantListDTO.getSelectText())
                )
                .page(page);
    }

    @Override
    public List<TenantInfo> getByNameOrPhone(String selectText) {
        return this.lambdaQuery()
                .and(StrUtil.isNotEmpty(selectText), tmp ->
                        tmp.like(TenantInfo::getPhone, selectText)
                                .or()
                                .like(TenantInfo::getName, selectText)
                )
                .list();
    }
}




